
package com.ostrich.project.controller;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.base.util.DateUtil;
import com.base.util.HtmlUtil;
import com.base.util.SessionUtils;
import com.base.web.BaseAction;
import com.ostrich.manpower.common.ImportUtil;
import com.ostrich.project.bean.TostPjMempushmoney;
import com.ostrich.project.bean.TostPjProjcttab;
import com.ostrich.project.service.impl.TostPjMempushmoneyService;
import com.ostrich.project.service.impl.TostPjProjcttabService;

/**
 * ClassName: Controller <br/>
 * date: 2013-5-9 下午03:07:38 <br/>
 * 
 * @author wangyinan
 * @version
 */
@Controller
@RequestMapping("/tostPjItemImputation")
public class TostPjItemImputationController extends BaseAction
{
	private final static Logger log= Logger.getLogger(TostPjItemImputationController.class);

	// Servrice start
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostPjMempushmoneyService<TostPjMempushmoney> tostPjMempushmoneyService; 
	
	@Autowired(required=false) //自动注入，不需要生成set方法了，required=false表示没有实现类，也不会报错。
	private TostPjProjcttabService<TostPjProjcttab> tostPjProjcttabService;
	/**
	 * ilook 首页
	 * @param url
	 * @param classifyId
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView  list(TostPjMempushmoney tostPjMempushmoney,HttpServletRequest request) throws Exception{
		Map<String,Object>  context = getRootMap();
//		List<TostPjMempushmoney> dataList = tostPjMempushmoneyService.queryByList(tostPjMempushmoney);
//		//设置页面数据
//		context.put("dataList", dataList);
		return forword("project/tabTostPjItemImputation",context); 
	}
	
	/**
	 * json 列表页面
	 * @param url
	 * @param classifyId
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/dataList")
	public void  dataList(TostPjMempushmoney tostPjMempushmoney,HttpServletRequest request,HttpServletResponse response) throws Exception{
		
		String startTime = request.getParameter("startTime")!=null?request.getParameter("startTime"):"";
		String endTime = request.getParameter("endTime")!=null?request.getParameter("endTime"):"";
		
		if(startTime!=""){
			String[] st = startTime.split("-");
			startTime = st[0]+st[1];
		}
		if(endTime!=""){
			String[] em = endTime.split("-");
			endTime = em[0]+em[1];
		}
		
		Map<String,Object> jsonMap = tostPjMempushmoneyService.resultajax(tostPjMempushmoney, startTime, endTime);
		HtmlUtil.writerJson(response, jsonMap);
	}
	
	@RequestMapping("/getId")
	public void getId(Integer id,HttpServletResponse response) throws Exception{
		Map<String,Object>  context = getRootMap();
		TostPjMempushmoney bean  = tostPjMempushmoneyService.queryById(id);
		if(bean  == null){
			sendFailureMessage(response, "没有找到对应的记录!");
			return;
		}
		context.put(SUCCESS, true);
		context.put("data", bean);
		HtmlUtil.writerJson(response, context);
	}
	
	@RequestMapping("/getProject")
	public void getProject(TostPjProjcttab tostPjProjcttab,HttpServletResponse response) throws Exception{
		List<TostPjProjcttab> list = tostPjProjcttabService.queryByList(tostPjProjcttab);
		HtmlUtil.writerJson(response,list);
	}
}
